
package com.noah.project.dao

import com.noah.project.model.Book
import com.noah.project.model.ReplyBook
import org.apache.ibatis.annotations.*
import org.springframework.stereotype.Repository


@Repository
interface BookDao {
    @Insert("INSERT INTO book(uid, title, pic, msg, bTime) VALUES(#{uid}, #{title}, #{pic}, #{msg}, #{bTime})")
    @Options(useGeneratedKeys = true, keyProperty = "bid", keyColumn = "bid")//可以返回当前的uid,不加这行返回的是插入的行数
    fun insert(book: Book): Long

    @Delete("DELETE FROM book WHERE bid =#{bid}")
    fun delete(bid: Long?): Long

    @Update("UPDATE book SET title = #{title}, pic = #{pic}, msg = #{msg}  WHERE bid = #{bid}")
    fun update(book: Book): Long

    @Select("SELECT * FROM book WHERE bid = #{bid}")
    fun findById(bid: Long?): Book?

    @Select("SELECT * FROM book")
    fun findAll(): List<Book>

    @Select("SELECT * FROM book WHERE uid = #{uid}")
    fun findBooksOfUser(uid: Long?): List<Book>

    @Select("SELECT * FROM book WHERE bid = #{bid}")
    fun findReplyById(bid: Long?): ReplyBook?
}
